
package ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.TextView;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Bean.PresentRecordBean;
import Utils.StringUtil;
import base.BaseViewHolder;
import base.SuperBaseAdapter;


/**
 * 提现列表适配器
 * Created by chenjian on 19/2/27.
 */
public class PresentChildAdapter extends SuperBaseAdapter<PresentRecordBean.ItemsBean.DataBean> {

    List<PresentRecordBean.ItemsBean.DataBean> mData = new ArrayList<>();
    Context mContext;

    public PresentChildAdapter(Context context, List<PresentRecordBean.ItemsBean.DataBean> data) {
        super(context, data);
        mContext = context;
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder holder, final PresentRecordBean.ItemsBean.DataBean item, final int position) {
        TextView status = holder.getView(R.id.lvpr_txt2);
        TextView info = holder.getView(R.id.lvpr_txt5);
        if (item.getType().equals("3")) {
            holder.setText(R.id.lvpr_txt1, "转购机款").setText(R.id.lvpr_txt3, item.getDate())
                    .setText(R.id.lvpr_txt4, StringUtil.getFormatPriceInt(mData.get(position).getMoney()) + "元")
                    .setText(R.id.lvpr_txt2, "支付成功");
            status.setText("支付成功");
            status.setTextColor(Color.parseColor("#0CA6F0"));
            info.setVisibility(View.GONE);
            if (item.getStatus().equals("3")) {
                status.setTextColor(Color.parseColor("#E52D24"));
                status.setText("已退款");
            }
        } else {

            String typeInfo = "";
            if (item.getType().equals("1")) {
                typeInfo = "分润提现-到";
            }  else if (item.getType().equals("2")) {
                typeInfo = "激活提现-到";


            }else if (item.getType().equals("10")) {
                typeInfo = "拓新提现-到";


            }
            else if (item.getType().equals("11")) {
                typeInfo = "成长提现-到";


            }
            else if (item.getType().equals("12")) {
                typeInfo = "领导提现-到";


            }

            try {
                holder.setText(R.id.lvpr_txt1, typeInfo + item.getCarname() + "(" + item.getCarnum().substring(item.getCarnum().length() - 4, item.getCarnum().length()) + ")");
                holder .setText(R.id.lvpr_txt3, item.getDate());
                holder .setText(R.id.lvpr_txt4, StringUtil.getFormatPriceInt(mData.get(position).getMoney()) + "元");
                if(item.getAutoGetMoney().equals("1")&&item.getType().equals("1")){
                    Spanned strB = Html.fromHtml("分润提现" + "<font color=#FF2F2F> (自动提现) </font>-到"+item.getCarname() + "(" + item.getCarnum().substring(item.getCarnum().length() - 4, item.getCarnum().length()) + ")");
                    holder.setText(R.id.lvpr_txt1, strB);
                }
                if(item.getAutoGetMoney().equals("1")&&item.getType().equals("2")){
                    Spanned strB = Html.fromHtml("激活提现" + "<font color=#FF2F2F> (自动提现) </font>-到"+item.getCarname() + "(" + item.getCarnum().substring(item.getCarnum().length() - 4, item.getCarnum().length()) + ")");
                    holder.setText(R.id.lvpr_txt1, strB);
                }

            } catch (Exception e) {
                holder.setText(R.id.lvpr_txt1, typeInfo + item.getCarname())
                        .setText(R.id.lvpr_txt3, item.getDate())
                        .setText(R.id.lvpr_txt4, StringUtil.getFormatPriceInt(mData.get(position).getMoney()) + "元");
                if(item.getAutoGetMoney().equals("1")&&item.getType().equals("1")){
                    Spanned strB = Html.fromHtml("分润提现" + "<font color=#FF2F2F> (自动提现) </font>-到"+item.getCarname() + "(" + item.getCarnum().substring(item.getCarnum().length() - 4, item.getCarnum().length()) + ")");
                    holder.setText(R.id.lvpr_txt1, strB);
                }
                if(item.getAutoGetMoney().equals("1")&&item.getType().equals("2")){
                    Spanned strB = Html.fromHtml("激活提现" + "<font color=#FF2F2F> (自动提现) </font>-到"+item.getCarname() + "(" + item.getCarnum().substring(item.getCarnum().length() - 4, item.getCarnum().length()) + ")");
                    holder.setText(R.id.lvpr_txt1, strB);
                }
            }

            if (item.getStatus().equals("1")) {
                status.setText("月结到账");
                //                              秒提                          推荐奖励                             自动提现
                if (item.getArrivalTime().equals("now")||item.getType().equals("4")||item.getAutoGetMoney().equals("1")) {
                    status.setText("处理中");
                }
                status.setTextColor(Color.parseColor("#FAB338"));
                info.setVisibility(View.GONE);
                info.setText("");
            } else if (item.getStatus().equals("2")) {
                status.setTextColor(Color.parseColor("#0CA6F0"));
                status.setText("提现成功");
                info.setVisibility(View.GONE);
                info.setText("");
            } else if (item.getStatus().equals("3")) {
                status.setTextColor(Color.parseColor("#E52D24"));
                status.setText("提现失败");
                info.setVisibility(View.VISIBLE);
                info.setText(item.getDetail());
            }
        }
    }


    @Override
    protected int getItemViewLayoutId(int position, PresentRecordBean.ItemsBean.DataBean item) {
        return R.layout.listviewgetpresentrecord_item2;
    }

}
